package com.biodiv.miracle.web.listener;

import com.biodiv.miracle.event.core.EventListener;
import com.biodiv.miracle.event.ErrorEvent;
import com.biodiv.miracle.web.context.ServletWebServerApplicationContext;

import java.util.logging.Logger;

/**
 * @author: tianquan
 * @date: 2025-05-28  09:41
 * @description: 容器刷新失败监听器
 */
public class ContextRefreshedErrorListener implements EventListener<ErrorEvent> {

    private final Logger logger = Logger.getLogger(ContextRefreshedErrorListener.class.getName());
    private final ServletWebServerApplicationContext applicationContext;

    public ContextRefreshedErrorListener(ServletWebServerApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Override
    public void onEvent(ErrorEvent event) {
        logger.severe("web server stop");
        applicationContext.stop();
    }

}
